/**
 * Created by wangfei on 2017/6/23.
 */
requirejs.config({
    baseUrl: '../../',
    paths:  {
        avalon: 'javascript/avalon.min',
        jquery: 'js/plugins/jquery/jquery-2.1.1.min',
        config: 'javascript/config',
        api: 'javascript/api',
        layer: 'js/plugins/layer1/layer'
    },
    shim: {
        api: {
            deps: ['jquery']
        },
        'layer':{
            deps: ['jquery']
        }
    }
});


(function(win, dom, requirejs, initVm){
    var vm;
    requirejs(['avalon', 'jquery', 'config', 'api', 'layer'], function(){
        //初始化vm
        vm = initVm(dom);
    });

})(window, document, requirejs, function(dom){
    var vm = avalon.define({
        $id:'container',
		form: {
			imageUrl: '',
			name: '',
			code: '',
			categoryName: '',
			contacts: '',
			phone: '',
			mainBiz: '',
			description: '',
			username: ''
		},
        showLayer: function() {
			layer.open({
				title: '修改密码',
				type: 1,
				area: ['400px','260px'],
				shadeClose: false,
				content: '<ul class="change-pwd"><li><label>原始密码</label><input type="password" id="oldPwd" placeholder="请输入原始密码"></li><li><label>新密码</label><input type="password" id="newPwd" placeholder="请输入新密码"></li><li><label>确认密码</label><input type="password" id="conPwd" placeholder="请确认新密码"></li></ul>',
				btn: ['确定', '取消'],
				yes: function(index,layero) {
					var form = {
						oldPwd: $('#oldPwd').val(),
						newPwd: $('#newPwd').val(),
						conPwd: $('#conPwd').val()
					}
					Api.supplierPwdUpdate(form, function(resp) {
						if(resp.code == 0) {
							layer.close(index);
						}
						layer.msg(resp.msg);
					});
				}
			})
        },
        search: function() {
			Api.supplierGet(function(resp) {
				if(resp.code == 0) {
					vm.form = resp.data;
				} else {
					layer.msg(resp.msg);
				}
			});
        }
    })
    avalon.scan(dom.body);
	vm.search();
    return vm;
});



